<template>
<view class="container">
		<view class="header">
			<view>
				<u-search :height="70" placeholder="输入场馆名称关键词搜索" v-model="venueName" @search="onSearchData" @custom="onSearchData"></u-search>
			</view>
		</view>
		<view class="wrapper" style="height: calc(100% - 90rpx);">
			<view class="main" >
				<scroll-view class="scroll" :scroll-y="true" :scroll-top="scrollTop" :show-scrollbar="false"
					:refresher-threshold="50" :refresher-triggered="refreshStatus" :lower-threshold="100"
					:scroll-with-animation="true" refresher-enabled="true" @refresherrefresh="onRefreshData"
					@scrolltolower="onLoadData" @scroll="onScroll">
					
					<view style="background-color: #ffffff;">
						<u-cell-group>
							<u-cell v-for="(item, index) in list" :key="index" @click="selectVenueReturn(index)"
							:icon="item.imgArry[0]" 
							:title="item.venueName" 
							:iconStyle="{width: '120rpx', height: '120rpx'}"
							isLink
							>
							
							<view
										slot="label"
										class="u-slot-label" style="color: #909193;letter-spacing: 0.7px; font-size: 28rpx; display: -webkit-box;
					text-overflow: ellipsis;
					overflow: hidden;
					-webkit-line-clamp: 2;
					line-clamp: 2;
					-webkit-box-orient: vertical;"
									>{{ item.address }}</view>
							
							</u-cell>
						</u-cell-group>
					</view>
					
					
					<view class="nullData" v-if="page == 1 && list.length <=0">
						<view style="text-align: center;">
							<view>
								<image src="../../../../static/image/notdata.png" class="nullImage"></image>
							</view>
							<view class="nullText">
								{{ searchResultText || '输入场馆名称关键词搜索' }}
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//当前页数
				page: 1,
				//每页显示条数
				size: 10,
				//列表数据
				list: [],
				//总页数
				pages: 0,
				//监听滚动
				scrollTop: 0,
				realScrollTop: 0,
				refreshStatus: false,
				//场馆名称
				venueName: '',
				//暂无数据
				searchResultText: ''
			}
		},
		onLoad() {
			
		},
		methods: {
			// 获取租借记录
			fetchList() {
				uni.showLoading({
					title: "加载中",
					mask: true
				})
				var params = {};
				params.current = this.page;
				params.size = this.size;
				params.venueName = this.venueName;
				this.$request({
					url: '/blade-merchant-app/merchant-app/venue/page',
					data: params
				}).then(res => {
					const {
						records = [],
							pages
					} = res.data;
					
					records.forEach(item => {
						item.imgArry = item.img.split(',');
					})
					
					if (this.page === 1) {
						this.searchResultText = (records.length<=0?'无数据':'')
						this.list = records;
					} else {
						this.list = this.list.concat(records);
					}
					this.pages = pages || 0;
					setTimeout(() => {
						this.refreshStatus = false;
						uni.hideLoading();
					}, 300);
				})
			},
			// 监听滚动事件
			onScroll(e) {
				this.realScrollTop = e.detail.scrollTop;
			},
			// 刷新数据
			onRefreshData() {
				this.refreshStatus = true;
				this.page = 1;
				this.list = [];
				this.fetchList();
			},
			// 加载数据
			onLoadData() {
				if (this.page < this.pages) {
					this.page += 1;
					this.fetchList();
				}
			},
			//搜索查询事件
			onSearchData() {
				if(!this.venueName){
					uni.$u.toast("请输入场馆名称关键词查询")
					return ;
				}
				this.page = 1;
				this.list = [];
				this.fetchList();
			},
			//选择数据后回调上一个页面
			selectVenueReturn(index){
				var venueObject = this.list[index];
				var venueName = venueObject.venueName;
				var venueId = venueObject.id;
				
				// 获取页面栈
				let pages = getCurrentPages();
				// 上一个页面实例
				let prevPage = pages[pages.length - 2];
				// 调用上一个页面的方法
				prevPage.selectPageReturn(venueId, venueName);
				
				//返回上一页面
				uni.navigateBack();
			}
		}
	}
</script>



<style lang="scss">
	page {
		height: 100%;
		overflow: hidden;
		background: #f1f1f1;

		.container {
			height: 100%;
			
			.header {
				padding: 20rpx 20rpx;
				background-color: #ffffff;
				height: 90rpx;
			}

			.wrapper {
				display: flex;
				flex-direction: column;
				height: 100%;

				.main {
					flex: 1;
					height: 100%;

					.scroll {
						height: 100%;

						.section {
							padding: 30rpx 30rpx 20rpx 30rpx;
							background: #ffffff;
							margin-bottom: 20rpx;
							margin-top: 20rpx;

							.card {
								
								
								.content {
									width: 100%;
									
									.pdleft {
										padding-left:30rpx;
										.title {
											font-size: 35rpx;font-weight: 600;
										}
										.desc {
											font-size: 30rpx;color: #666666;line-height: 50rpx;
										}
										.price {
											color: red;
											.rmb {
												font-size: 30rpx;
											}
											.amount {
												font-size: 33rpx;
											}
										}
									}
									
									
								}
								
							}

							
						}
					}
				}
			}
		}
		
		.nullData {
			height: 100%;
			display: flex;
			-webkit-box-pack: center;
			justify-content: center;
			-webkit-box-align: center;
			align-items: center;
			
			.nullImage {
				width: 120px;height: 120px;
			}
			.nullText {
				color:#666666;font-size:29rpx;padding-top:15rpx;text-align: center;
			}
			
		}
	}
	
</style>